//=============================================================================
// M41A Pulse Rifle HOORAA!
//=============================================================================
class M41AAssaultRifle extends M4AssaultRifle
	config(user);
	
#exec OBJ LOAD FILE=AKFFonts.utx
#exec obj load file="AliensKFWeapons_T.utx"
#exec obj load file="AliensKFWeapons_A.ukx"
#exec obj load file="BDFonts.utx"
#exec obj load file="AliensKFWeapons_SM.usx"

var() ScriptedTexture MyScriptedTexture;
var() Shader AmmoCounter;
var string MyMessage;
var int MyHealth;
var   Font MyFont;
var   Font MyFont2;
var   Font SmallMyFont;
var  color MyFontColor;
var  color MyFontColor2;
var int OldValue;

var     float               ForceZoomOutTime;

// Don't use alt fire to toggle
simulated function AltFire(float F){}
// Don't switch fire mode
exec function SwitchModes(){}

simulated function WeaponTick(float dt)
{
    super.WeaponTick(dt);

    if( ForceZoomOutTime > 0 )
    {
        if( bAimingRifle )
        {
    	    if( Level.TimeSeconds - ForceZoomOutTime > 0 )
    	    {
                ForceZoomOutTime = 0;

            	ZoomOut(false);

            	if( Role < ROLE_Authority)
        			ServerZoomOut(false);
    		}
		}
		else
		{
            ForceZoomOutTime = 0;
		}
	}
}

// Force the weapon out of iron sights shortly after firing the 203 grenade
simulated function bool StartFire(int Mode)
{
    if( super.StartFire(Mode) )
    {
        if( mode == 1 )
        {
            ForceZoomOutTime = Level.TimeSeconds + 0.4;
        }
        return true;
    }

    return false;
}

simulated function bool CanZoomNow()
{
    return ( !FireMode[1].bIsFiring &&
           ((FireMode[1].NextFireTime - FireMode[1].FireRate * 0.2) < Level.TimeSeconds + FireMode[1].PreFireTime));
}

function bool AllowReload()
{
	if( (FireMode[1].NextFireTime - FireMode[1].FireRate * 0.1) > Level.TimeSeconds + FireMode[1].PreFireTime )
	{
		return false;
	}

	return super.AllowReload();
}

simulated function bool ReadyToFire(int Mode)
{
    // Don't allow firing while reloading the shell
	if( (FireMode[1].NextFireTime - FireMode[1].FireRate * 0.06) > Level.TimeSeconds + FireMode[1].PreFireTime )
	{
		return false;
	}

    return super.ReadyToFire(Mode);
}


simulated final function SetTextColor( byte R, byte G, byte B )
{
	MyFontColor.R = R;
	MyFontColor.G = G;
	MyFontColor.B = B;
	MyFontColor.A = 255;


}

simulated final function SetTextColor2( byte R, byte G, byte B )
{
	MyFontColor2.R = R;
	MyFontColor2.G = G;
	MyFontColor2.B = B;
	MyFontColor2.A = 255;

 }

simulated function RenderOverlays( Canvas Canvas )
{


    local float fHeight;
    local float fWidth;
    local float fwidth2;
    local float fheight2;
    local float fX;
    local float fY;
    local float fy2;
    local float fx2;



    fX = Canvas.ClipX * 0.725;
    fY = Canvas.ClipY * 0.940;
    fX2 = Canvas.ClipX * 0.725;
    fY2 = Canvas.ClipY * 0.935;
    fWidth = Canvas.ClipX * 0.0500000;
    fHeight = Canvas.ClipY * 0.03500000;
    fwidth2 = canvas.clipx * 0.05000000;
    fHeight2 = canvas.clipy * 0.0475000;

    //-----------------------------------------------------------

      Canvas.SetPos(fX2, fY2);
//    Canvas.Style = ERenderStyle.STY_Masked;		  
/*    Canvas.DrawTile(Texture'KillingFloorHud.HUD.Hud_BOX_128x64', fWidth2, fHeight2, 0, 0, 128, 64);   


    if(AmmoAmount(1) == 1)
    {
	Canvas.SetPos(fX, fY);		  
        Canvas.DrawTile(SecAmmo1, fWidth, fHeight, 0, 0, 128, 64);
    }	  

	    if(AmmoAmount(1) == 2)
    {
  	Canvas.SetPos(fX, fY);		  
    	Canvas.DrawTile(SecAmmo2, fWidth, fHeight, 0, 0, 128, 64);
    }	 
	
	    if(AmmoAmount(1) >= 3)
    {
	Canvas.SetPos(fX, fY);		  
        Canvas.DrawTile(SecAmmo3, fWidth, fHeight, 0, 0, 128, 64);
    }	 
*/        

		  
 	if( AmmoAmount(0) <= 0 )
	{
		if( OldValue!=-5 )
		{
			OldValue = -5;
	//		Skins[5] = ScopeRed;
			MyFont = SmallMyFont;
			SetTextColor(218,18,18);
			MyMessage = "Empty";
			++MyScriptedTexture.Revision;
		}
	}
	else if( bIsReloading )
	{
		if( OldValue!=-4 )
		{
			OldValue = -4;
			MyFont = SmallMyFont;
			SetTextColor(32,187,112);
			MyMessage = "RL";
			++MyScriptedTexture.Revision;
		}
	}
	else if( OldValue!=(MagAmmoRemaining+1) )
	{
		OldValue = MagAmmoRemaining+1;
//		Skins[5] = ScopeGreen;
		MyFont = Default.MyFont;

		if ((MagAmmoRemaining ) <= (MagCapacity/2))
			SetTextColor(32,187,112);
		if ((MagAmmoRemaining ) <= (MagCapacity/3))
		{
			SetTextColor(218,18,18);
//			Skins[5] = ScopeRed;
		}
		if ((MagAmmoRemaining ) >= (MagCapacity/2))
			SetTextColor(76,148,177);
		MyMessage = String(MagAmmoRemaining);

		++MyScriptedTexture.Revision;
	}

	MyScriptedTexture.Client = Self;
	//Skins[5] = AmmoCounter;
	Super.RenderOverlays(Canvas);
	MyScriptedTexture.Client = None;
	//Skins[5] = None;
}
simulated function RenderTexture( ScriptedTexture Tex )


{
	local int w, h;
/*
	// Ammo
	Tex.TextSize( MyMessage, MyFont,  w, h );
	Tex.DrawText( ( Tex.USize / 2 ) - ( w / 2 ), ( Tex.VSize / 2 ) - ( h / 1.2 ),MyMessage, MyFont, MyFontColor );

*/

	Tex.TextSize( MyMessage, MyFont2,  w, h );	
//	Tex.TextSize(AmmoAmount(1), MyFont2,w,h); 
	Tex.DrawText( ( Tex.USize / 2 ) - ( w / 2.2 ), ( Tex.VSize / 2 ) - ( h / 2.0 ),/*AmmoAmount(1)*/MyMessage, MyFont, MyFontColor2 );
}

defaultproperties
{
	 bHasSecondaryAmmo=True
	 bReduceMagAmmoOnSecondaryFire=False
	
     MyScriptedTexture=ScriptedTexture'AliensKFWeapons_T.AmmoText'
     MyFont=Font'BDFonts.DigitalMed'
     MyFont2=Font'BDFonts.DigitalMed'
     SmallMyFont=Font'BDFonts.DigitalMed'
     MyFontColor=(B=177,G=148,R=76,A=255)
     MyFontColor2=(B=18,G=18,R=218,A=255)
     //SecAmmo1=Texture'AliensKFWeapons_T.HUD.HUD_M41ANADE1'
     //SecAmmo2=Texture'AliensKFWeapons_T.HUD.HUD_M41ANADE2'
     //SecAmmo3=Texture'AliensKFWeapons_T.HUD.HUD_M41ANADE3'
     MagCapacity=99
     ReloadRate=2.000000
     ReloadAnim="Reload"
     ReloadAnimRate=1.500000
     WeaponReloadAnim="Reload_SCAR"
     HudImage=Texture'AliensKFWeapons_T.HUD.HUD_M41A_unselected'
     SelectedHudImage=Texture'AliensKFWeapons_T.HUD.HUD_M41A_selected'
     Weight=6.000000
     bHasAimingMode=True
     IdleAimAnim="Idle_Iron"
     StandardDisplayFOV=55.000000
     bModeZeroCanDryFire=True
     TraderInfoTexture=Texture'AliensKFWeapons_T.Trader.Trader_M41A'
     PlayerIronSightFOV=70.000000
     ZoomedDisplayFOV=45.000000
     FireModeClass(0)=Class'AliensKFWeapons.M41AFire'
     FireModeClass(1)=Class'AliensKFWeapons.M41AALTFire'
     PutDownAnim="PutDown"
     SelectSound=Sound'AliensKFWeapons_S.Select'
     SelectForce="SwitchToAssaultRifle"
     AIRating=0.550000
     CurrentRating=0.550000
     bShowChargingBar=True
//     AmmoClass(0)=Class'AliensKFWeapons.M41AAmmo'
//     AmmoClass(1)=Class'AliensKFWeapons.M41AProjectileAmmo'
     Description="The M41A Pulse Rifle from the movie Aliens."
     EffectOffset=(X=100.000000,Y=25.000000,Z=-10.000000)
     DisplayFOV=55.000000
     Priority=15
     SleeveNum=1
     CustomCrosshair=11
     CustomCrossHairTextureName="Crosshairs.HUD.Crosshair_Cross5"
     InventoryGroup=4
     GroupOffset=7
     PickupClass=Class'AliensKFWeapons.M41APickup'
     PlayerViewOffset=(X=20.000000,Y=19.000000,Z=3.000000)
     BobDamping=6.000000
     AttachmentClass=Class'AliensKFWeapons.M41AAttachment'
     IconCoords=(X1=245,Y1=39,X2=329,Y2=79)
     ItemName="M41A"
     Mesh=SkeletalMesh'AliensKFWeapons_A.M41APulseRifle'
     Skins(0)=Combiner'AliensKFWeapons_T.M41A_cmb'
     TransientSoundVolume=5.250000
     
}
